<template>
  <view class="container">
	  <view class="" style="color: red;padding: 30rpx 0;">
	  	<text>当前用户的所有新闻数据，包含草稿箱中的</text>
	  </view>
	   <!-- where="user_id==$cloudEnv_uid||comment_status==1" -->
    <unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}" 
	collection="opendb-news-articles" where="user_id==$cloudEnv_uid" 
	field="user_id,category_id,title,content,excerpt,article_status,comment_status,avatar,publish_date,last_modify_date">
      <view v-if="error">{{error.message}}</view>
      <view v-else-if="data">
        <uni-list>
          <uni-list-item v-for="(item, index) in data" :key="index" showArrow :clickable="true" @click="handleItemClick(item._id)"
		 :title="item.title" :note="item.excerpt" :thumb="item.avatar?item.avatar:'/static/image/QQ.png'"
		 :rightText='handleStatus(item.article_status)'>
          </uni-list-item>
        </uni-list>
      </view>
      <uni-load-more :status="loading?'loading':(hasMore ? 'more' : 'noMore')"></uni-load-more>
    </unicloud-db>
    <uni-fab ref="fab" horizontal="right" vertical="bottom" :pop-menu="false" @fabClick="fabClick" />
  </view>
</template>

<script>
  export default {
    data() {
      return {
        loadMore: {
          contentdown: '',
          contentrefresh: '',
          contentnomore: ''
        },
      }
    },
    onPullDownRefresh() {
      this.$refs.udb.loadData({
        clear: true
      }, () => {
        uni.stopPullDownRefresh()
      })
    },
    onReachBottom() {
      this.$refs.udb.loadMore()
    },
    methods: {
		handleStatus(status){
			if(status==1){
				return '公开发表'
			}else{
				return '草稿箱'
			}
		},
      handleItemClick(id) {
        uni.navigateTo({
          url: './detail?id=' + id
        })
      },
      fabClick() {
        // 打开新增页面
        uni.navigateTo({
          url: './add',
          events: {
            // 监听新增数据成功后, 刷新当前页面数据
            refreshData: () => {
              this.$refs.udb.loadData({
                clear: true
              })
            }
          }
        })
      }
    },
  }
</script>

<style>
</style>
